<template>
    <v-chart class="chart" :option="option" />
</template>

<script setup>
import { use } from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { BarChart } from 'echarts/charts';
import {
    TitleComponent,
    TooltipComponent,
    LegendComponent,
    GridComponent,
} from 'echarts/components';
import VChart, { THEME_KEY } from 'vue-echarts';
import { ref, provide } from 'vue';

use([
    CanvasRenderer,
    BarChart,
    TitleComponent,
    TooltipComponent,
    LegendComponent,
    GridComponent,
]);

provide(THEME_KEY, 'dark');

// ['ZSXM', 'ZSXMMC', 'BYSR', 'SNTY', 'BYZJE', 'BYZJL', 'LJSR', 'SNTQ', 'LJZJE', 'LJZJL'],
const taxbyxm = [
    ['ZSXM', 'ZSXMMC', 'BYSR', 'SNTY', 'BYZJE', 'BYZJL', 'LJSR', 'SNTQ', 'LJZJE', 'LJZJL'],
    [10101, '增值税', 600516, 552430, 48086, '8.7', 4515947, 6544494, -2028547, '-31.0'],
    [10102, '消费税', 248743, 175007, 73736, '42.1', 5843029, 5495351, 347678, '6.3'],
    [10103, '营业税', 83, -215, 298, '-138.6', 6797, -643, 7440, '-1157.1'],
    [10104, '企业所得税', 30422, -14496, 44918, '-309.9', 3168073, 3585058, -416985, '-11.6'],
    [10106, '个人所得税', 131865, 162128, -30263, '-18.7', 1366933, 1387305, -20372, '-1.5'],
    [10107, '资源税', 617, 745, -128, '-17.2', 7559, 7108, 451, '6.3'],
    [10109, '城市维护建设税', 41950, 43164, -1214, '-2.8', 532197, 568378, -36181, '-6.4'],
    [10110, '房产税', 83141, 77312, 5829, '7.5', 431908, 396193, 35715, '9.0'],
    [10111, '印花税', 12405, 30627, -18222, '-59.5', 199317, 180003, 19314, '10.7'],
    [10112, '城镇土地使用税', 45511, 46150, -639, '-1.4', 205990, 191278, 14712, '7.7'],
    [10113, '土地增值税', 175334, 151419, 23915, '15.8', 1315341, 1318517, -3176, '-0.2'],
    [10114, '车船税', 12337, 10967, 1370, '12.5', 133076, 109100, 23976, '22.0'],
    [10116, '车辆购置税', 24698, 26286, -1588, '-6.0', 337887, 420894, -83007, '-19.7'],
    [10118, '耕地占用税', 3186, 12508, -9322, '-74.5', 79813, 86637, -6824, '-7.9'],
    [10119, '契税', 121782, 144771, -22989, '-15.9', 933145, 1250187, -317042, '-25.4'],
    [10120, '烟叶税', '-', '-', '-', '-', 9462, 6633, 2829, '42.7'],
    [10121, '环境保护税', 355, 389, -34, '-8.7', 8088, 5721, 2367, '41.4']
];

function transform(arr) {
    const newarr = arr[0].map((col, i) => arr.map(row => row[i]));
    return newarr;
};

var tarr = transform(taxbyxm);
console.log(tarr);

var xms = taxbyxm.map(function (value, index) {
    return value[1];
});
//xms = xms.slice(1,xms.length);
console.log(xms);

var ljsrs = taxbyxm.map(function (value, index) {
    return value[6];
})

const option = ref({
    title: {
        text: '分税种结构图'
    },
    datasets: taxbyxm,
    series: [{
        name: tarr[1],
        type: 'pie',
        radius: '60%',
        data: ljsrs
    }]
});
</script>

<style scoped>
.chart {
    height: 600px;
}
</style>